package com.feidian.helper.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

import com.feidian.helper.R;
import com.feidian.helper.bean.Item;

/**
 * 
 * @author linxingqianglai or lxq
 * @category 2015.9.20 
 * 
 * 
 *
 */
public class NewsAdapter extends BaseAdapter {

	private Context mContext;
	private List<Item> newsList = null;

	public NewsAdapter(Context context, List<Item> newsList) {
		mContext = context;
		this.newsList = newsList;
	}

	@Override
	public int getCount() {
		return newsList.size();
	}

	@Override
	public Item getItem(int position) {
		return newsList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			LayoutInflater inflater = LayoutInflater.from(mContext);
			convertView = inflater.inflate(R.layout.news_item, null);
			holder.nameTv = (TextView) convertView.findViewById(R.id.name);
			holder.titleTv = (TextView) convertView.findViewById(R.id.title);
			holder.pastTimeTv = (TextView) convertView
					.findViewById(R.id.past_time);
			holder.contentTv = (TextView) convertView
					.findViewById(R.id.content);
			holder.priceTv = (TextView) convertView.findViewById(R.id.price);
			holder.endlineTv = (TextView) convertView
					.findViewById(R.id.endline);
			holder.honestyRatingBar = (RatingBar) convertView
					.findViewById(R.id.ratingBar);
			holder.stateTv=(TextView)convertView.findViewById(R.id.state);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.nameTv.setText(newsList.get(position).getName());
		holder.titleTv.setText(newsList.get(position).getTitle());
		holder.pastTimeTv.setText(newsList.get(position).getPastTime());
		holder.contentTv.setText(newsList.get(position).getContent());
		holder.priceTv.setText(newsList.get(position).getPrice());
		holder.endlineTv.setText(newsList.get(position).getEndline());
		holder.honestyRatingBar.setRating(Float.parseFloat(newsList.get(
				position).getHonesty()));
		return convertView;
	}

	static class ViewHolder {
		TextView nameTv;// 名字
		TextView titleTv;// 类别
		TextView pastTimeTv;// 离发布的时间差
		TextView contentTv;// 求助内容
		TextView priceTv;// 求助金额
		TextView endlineTv;// 截止日期
		RatingBar honestyRatingBar;// 发帖信用度
		TextView stateTv;
	}

}
